using BCW;
using I2.Loc;
using UnityEngine;

public class LeagueHUD : MonoBehaviour
{
	public UIBasicSprite leagueTexture;

	public UILabel leagueName;

	public UILabel cupsCount;

	public UISprite cupsBar;

	private void Start()
	{
		SetLeagueHUD(League.none);
	}

	private void OnEnable()
	{
		SwitchLanguage.onChangeLanguage += SetLocalization;
		CupsManager.leagueChanged += SetLeagueHUD;
		CupsManager.cupsChanged += SetCups;
	}

	private void OnDisable()
	{
		SwitchLanguage.onChangeLanguage -= SetLocalization;
		CupsManager.leagueChanged -= SetLeagueHUD;
		CupsManager.cupsChanged -= SetCups;
	}

	private void OnDestroy()
	{
		SwitchLanguage.onChangeLanguage -= SetLocalization;
		CupsManager.leagueChanged -= SetLeagueHUD;
		CupsManager.cupsChanged -= SetCups;
	}

	public void SetLeagueHUD(League league)
	{
		SetLeague();
		SetCups(0);
	}

	private void SetLeague()
	{
		leagueTexture = leagueTexture.ReplaceForCurrentPlatform();
		leagueTexture.LoadTextureAndAlphaMask("LigasIcons/", CupsManager.CurrentLeague.ToString());
		SetLocalization();
	}

	private void SetCups(int cups)
	{
		cupsCount.text = CupsManager.Cups.ToString();
		if (cupsBar != null)
		{
			cupsBar.fillAmount = CupsManager.GetLeagueFillAmount;
		}
	}

	private void SetLocalization()
	{
		leagueName.text = ScriptLocalization.Get("Game_Common/" + CupsManager.CurrentLeague) + "\n" + ScriptLocalization.Get("Game_Common/lobby_label_league");
	}
}
